package com.henry.others;

import java.util.function.Function;

interface IntToInt {
    int f(int val);
}

public class LambdaDemo {

    static int getVal(IntToInt function, int val) {
        return function.f(val);
    }

    public static void main(String[] args) {

        IntToInt addOne = new IntToInt() {
            @Override
            public int f(int val) {
                return val + 1;
            }
        };

        IntToInt addTwo = val -> val + 2;

        IntToInt multiplyThree = val -> {
            return val * 3;
        };

        System.out.println(getVal(addOne, 18));
        System.out.println(getVal(addTwo, 18));
        System.out.println(getVal(multiplyThree, 18));
        System.out.println(getVal(val -> 2 * val + 1, 18));

        Function<String, String> sayHello = s -> "Hello " + s + "!";
        System.out.println(sayHello.apply("John"));
        System.out.println(sayHello.apply("Nancy"));
    }
}
